import 'vux/src/styles/reset.less';
import './spread.scss'
import {
  Swiper,
  Scroller,
  Tab,
  TabItem,
  Sticky,
  Flexbox,
  FlexboxItem,
  XInput,
  Group,
  XButton,
  Cell,
  CheckIcon,
  PopupPicker,
  XAddress,
  ChinaAddressV4Data,
  Datetime,
  ToastPlugin,
  Confirm,
} from 'vux'

import {
  hostImg
} from 'js/host-config'
import {
  fetch,
  rap
} from 'js/fetch.js'

import utils from 'js/utils.js'
import {
  cookie
} from 'vux'


let url = {
  postShare: 'api/user/',
  
}
url = rap(url)
import Myhead from 'components/head/head.vue'
// import Slide from 'components/slide/slide.vue'
import Top from 'components/top/top.vue'
// import Search from 'components/search/search.vue'
import Foot from 'components/foot/foot.vue'

import Booklist from 'components/booklist/booklist.vue'
import { checkphone } from 'js/validate.js'
import mixin from 'js/mixin.js'

new Vue({
  el: '#body',
  data: {
    tel: '',
    user_id:""
  },
  created() {
    this.user_id  = utils.getQuery('user_id')

  },
  methods: {
    checkTel(value) {
      this.isCheckTel = checkphone(value)
      return {
        valid: this.isCheckTel,
        msg: '请输入合格的手机号'
      }
    },
    reg(){
      //  1/invite'
      fetch('post', `${url.postShare}${this.user_id}/invite`, {
       phone:this.tel,
       user_id :this.user_id
      }).then(res => {

       if (res.status >= 200 && res.status <= 300) {
        window.location.href='./'
        
       } else {
         this.$vux.toast.show({
           text: res.data.message,
           type: 'warn',
           onShow() {
             //console.log('Plugin: I\'m showing')
           },
           onHide() {
             //console.log('Plugin: I\'m hiding')
           }
         })
       }
     })
   },
  },
  components: {
    Swiper,
    Scroller,
    Tab,
    TabItem,
    Sticky,
    Flexbox,
    FlexboxItem,
    XInput,
    Group,
    XButton,
    Cell,
    CheckIcon,
    PopupPicker,
    XAddress,
    ChinaAddressV4Data,
    Datetime,
    ToastPlugin,
    Confirm,
  },
  mixins: [mixin]
})
